package sistema.web.servlet.servicio;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sistema.web.bussiness.IServicioBussiness;
import sistema.web.bussiness.impls.ServicioBussiness;
import sistema.web.dtos.ServicioDTO;

/**
 * Servlet implementation class ServicioModificar_Servlet
 */
@WebServlet("/ServicioModificar_Servlet")
public class ServicioModificar_Servlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServicioModificar_Servlet() {
        super();
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		
		String codigo = request.getParameter("codigo");
		
		IServicioBussiness bus = new ServicioBussiness();
		List<ServicioDTO> listServicio = bus.listar("idServicio", codigo);
		
		if(listServicio != null) {
			ServicioDTO dtoServicio = listServicio.get(0);
			
			request.setAttribute("codigo", dtoServicio.getIdServicio());
			request.setAttribute("nombre", dtoServicio.getNombre());
			request.setAttribute("costo", dtoServicio.getCosto());
			request.setAttribute("descripcion", dtoServicio.getContenidoHTML());
		}
		
		RequestDispatcher rd = request.getRequestDispatcher("/regi_servicio.jsp");
        rd.forward(request, response);
	}
}